import {
  createRouter,
  createWebHistory,
  createWebHashHistory,
} from "vue-router";
import { defineAsyncComponent } from "vue"; //异步组挂载器
import { el, fa } from "element-plus/es/locale";
const router = createRouter({
  history: createWebHistory("/"),
  routes: [
    //登录
    {
      path: "/login",
      name: "login",
      component: defineAsyncComponent(() => import("../view/login/index.vue")),
    },
    {
      path: "/registration",
      name: "registration",
      component: defineAsyncComponent(() => import("../view/registration/index.vue")),
    },
    {
      path: "/",
      name: "home",
      component: defineAsyncComponent(() => import("../view/home/index.vue")),
      redirect: "/test1",
      children: [
        {
          path:'/test',
          name:'test',
          meta:{
            title: 'test',
            icon: "../../src/assets/icon/cw.png",
            name:'test',
            id:0
          },
          redirect:'/test1',
          children: [
            {
              path: "/test1",
              name: "test1",
              component: defineAsyncComponent(
                  () => import("../view/myTest/index.vue")
              ),
              meta: { name: "test1", title: "玩儿", id: 19,parentId:0  },
            },
          ],
        },
      ],
    },
  ],
});

// 全局路由守卫
router.beforeEach((to,from)=>{
 //  let isAuthenticated=localStorage.getItem('userId')
 //  const token = isAuthenticated
 //  if(to.path !== '/login'&&to.path!=='/registration'){
 //    if(!token){
 //     return '/login'
 //    }
 //  }else if(to.path == '/login'||to.path=='/registration'){
 //   if(token){
 //    return from.path
 //   }
 //  }
 })


export default router;
